/**
 *  接单管理页面js
 * 版权所有：上海戈品投资管理有限公司
 *   author king
     功能说明：接单管理
     创建日期：2015-10-12
     修改记录：
     备注说明：
 */


$(document).ready(function() {
	receiveOrderList();
	 $(".date").datepicker({
	        todayBtn: "linked",
	        keyboardNavigation: false,
	        forceParse: false,
	        calendarWeeks: true,
	        autoclose: true
	    });
});

/**
 * 接单管理查询
 * @returns
 */
var receiveOrderList = function(){

	var filtrateEmp=$("#selectList").val();
	var senderNickName=$("#senderNickName").val();
	var courierName=$("#courierName").val();
	var courierPhone=$("#courierPhone").val();
	var timeType=$("#TimeSelectList").val();
	var checkTime=$("#checkTime").val();
	
	 var datas =  {"p":"expressOrder","m":"query","status":filtrateEmp,"senderNickName":senderNickName,"courierName":courierName,"courierPhone":courierPhone,"timeType":timeType,"checkTime":checkTime};
	 var columnDefine = {"id":"编号","rollupatetime":"更新日期","name_wx":"昵称","real_name":"真实姓名","telephone":"手机号","company":"快递公司","userType":"用户类型","rollStatus":"状态","yellowRestoretime":"解封日期","ext1":"操作日志"};
	 var formatters={
	            "createTime": function (column, rowData)
	            {
	            	if( rowData.createTime > 0 )
	            	{
	            		return timeFormatTrans(rowData.createTime);
	            	}	
	            	return '';
	            },
	            "receiveOrderTime": function (column, rowData)
	            {
	            	if( rowData.receiveOrderTime > 0 )
	            	{
	            		return timeFormatTrans(rowData.receiveOrderTime);
	            	}	
	            	return '';
	            },
	            "cancelOrderTime": function (column, rowData)
	            {
	            	if( rowData.cancelOrderTime > 0 )
	            	{
	            		return timeFormatTrans(rowData.cancelOrderTime);
	            	}	
	            	return '';
	            },
	            "sendTime": function (column, rowData)
	            {
	            	if( rowData.sendTime > 0 )
	            	{
	            		return timeFormatTrans(rowData.sendTime);
	            	}	
	            	return '';
	            },
	            "receiveOrderStatus": function (column, rowData)
	            {
    				if(rowData.receiveOrderStatus==1){
						return "已接单";
					}else if(rowData.receiveOrderStatus==2){
						return "拒绝接单";
					}else if(rowData.receiveOrderStatus==3){
						return "取消订单";
					}else if(rowData.receiveOrderStatus==4){
						return "订单超时失效";
					}else if(rowData.receiveOrderStatus==5){
						return "已领红包";
					}else if(rowData.receiveOrderStatus==0){
						return "未接单";
					}else{
						return "";
					}
	            }
	 };
	 var buttons =''; //操作按钮
		buttons+='<p>';
		buttons+='<button type=\'button\' class=\'btn btn-w-m btn-info\' onclick="showEvaluates();">查看评价</button>';
		buttons+='</p>';
	hui.pager('service',datas ,"dataList", columnDefine , formatters , buttons ); //分页查询
	 
};

var getTheSureTime=function(emp){
	return emp>9?emp:"0"+emp;
}
//时间格式转换
var timeFormatTrans=function(time){
	var newTime= new Date(time);
	var rowText=newTime.getFullYear()+'-'+getTheSureTime((newTime.getMonth()+1))+'-'
	+getTheSureTime(newTime.getDate())+' '+getTheSureTime(newTime.getHours())+':'
	+getTheSureTime(newTime.getMinutes())+':'+getTheSureTime(newTime.getSeconds());
	return rowText;
};

/**
 * 导出数据
 * @returns
 */
var exportDatas = function(){
	
	var filtrateEmp=$("#selectList").val();
	var senderNickName=$("#senderNickName").val();
	var courierName=$("#courierName").val();
	var courierPhone=$("#courierPhone").val();
	var timeType=$("#TimeSelectList").val();
	var checkTime=$("#checkTime").val();
	var datas =  {"p":"expressOrder","m":"query","exportData":1 ,"status":filtrateEmp,"senderNickName":senderNickName,"courierName":courierName,"courierPhone":courierPhone,"timeType":timeType,"checkTime":checkTime};
	var rjson=common.ajaxRequest('service', datas , "POST");
	if(rjson && rjson.result == 0)
	{
		if(rjson.exportDataSql)
		{
			dataUrl=rjson.exportDataSql;
		}
		else
		{
			common.showMsg('error', '', '导出数据未成功，请刷新重试');
		}
	}
	else
	{
		common.showMsg('error', '', '导出数据操作失败！');
	}
	if(!common.validVar(dataUrl)){
		return;		
	}
	var data = {"p":"exportData","sql":dataUrl,"m":"exportData"};
	var json = common.ajaxRequest('service', data , 'POST');
	common.showMsg('info', '', json.message);
	window.open(json.excelFile);
};

/**
 * 查看评价
 * @returns
 */
var showEvaluates = function(){
	var datas = $('#pop_win .data').text();
	var json = eval('('+datas+')');
	var id = json.id;
	window.location.href='page?p=page/courierEvaluate&orderId='+id;
};


